function calculateFee()
{
	if ((document.getElementById("addFee").checked)){
		document.getElementById("feeCovered").innerHTML = parseFloat(document.getElementById("preview").innerHTML).toFixed(2);
		document.getElementById("total").innerHTML = (parseFloat(document.getElementById("donation").innerHTML) + parseFloat(document.getElementById("feeCovered").innerHTML)).toFixed(2);
	} else {
		document.getElementById("feeCovered").innerHTML = "0.00";
		document.getElementById("total").innerHTML = (parseFloat(document.getElementById("donation").innerHTML)).toFixed(2);
	} 
}
function calculatePreviewFee()
{	
	if ((document.getElementById("cash").value != "") && (!isNaN(document.getElementById("cash").value))){
		var taxAmount = ((parseFloat(document.getElementById("cash").value) * .022) + .30);	
		document.getElementById("preview").innerHTML = taxAmount.toFixed(2);
		document.getElementById("donation").innerHTML = (parseFloat(document.getElementById("cash").value)).toFixed(2);
		calculateFee();
	} else {
		document.getElementById("preview").innerHTML = "0.30";
		document.getElementById("donation").innerHTML = "0.00";
		calculateFee();
	}
}
function getTotalDonation()
{
	document.getElementById("finalTotal").value = document.getElementById("total").innerHTML;
}
function checkForOneTime()
{
	if ((document.getElementById("times").value) == 1){
		document.getElementById("recurring").style.display = "none";
		document.getElementById("finalTotal").name = "amount";
		document.getElementById("command").value = "_xclick";
		changePurpose(getPurposeChecked());
	} else {
		document.getElementById("recurring").style.display = "block";
		document.getElementById("finalTotal").name = "a3";
		document.getElementById("command").value = "_xclick-subscriptions";
		changePurpose(getPurposeChecked());
	}
}
function showEventRegistrationForm()
{
	var formDiv = document.getElementById("registrationForm");
	var displayForm = document.getElementById("displayForm");
	if (formDiv.style.display == "none"){
		formDiv.style.display = "block";
		displayForm.innerHTML = "- Hide Registration";
	} else {
		formDiv.style.display = "none";
		displayForm.innerHTML = "+ Register For Event";
	}
}
function updatePrice()
{
	var input = document.getElementById("numPeople").value;
	if (isNaN(input) || (input == "")){
		input = 0;
	} else{
		input = Math.round(parseFloat(input));
	}
	var checkedState = document.getElementById("addFee").checked;
	try {
		var costPerPerson = document.getElementById("costPerPerson").innerHTML;
	} catch(err){
		var costPerPerson = 0;
	}
	try {
		var costPerCouple = document.getElementById("costPerCouple").innerHTML;
	} catch(err) {
		var costPerCouple = (parseFloat(costPerPerson)*2);
	}
	if (input%2 == 0){
		var baseCost = (input/2) * parseFloat(costPerCouple);
	} else {
		var baseCost = ((input - 1)/2) * parseFloat(costPerCouple);
		if (costPerPerson != 0){
			baseCost = baseCost + parseFloat(costPerPerson);
		} else {
			baseCost = baseCost + parseFloat(costPerCouple);
		}
	}
	try {
		var maxCost = document.getElementById("maxCost").innerHTML;
	} catch(err){
		var maxCost = null;
	}
	if (maxCost != null){
		if (baseCost >= parseFloat(maxCost)){
			baseCost = parseFloat(maxCost);
		}
	}
	var feeCovered = (parseFloat(baseCost) * .022) + .30;
	document.getElementById("cost").innerHTML = baseCost.toFixed(2);
	document.getElementById("preview").innerHTML = feeCovered.toFixed(2);
	if (checkedState){
		document.getElementById("feeCovered").innerHTML = feeCovered.toFixed(2);
	} else {
		document.getElementById("feeCovered").innerHTML = "0.00";
	}
	var feePaying = document.getElementById("feeCovered").innerHTML;
	var grandTotal = parseFloat(baseCost) + parseFloat(feePaying);
	document.getElementById("total").innerHTML = grandTotal.toFixed(2);
}
function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}	
	return null;
}
function changePurpose(val)
{
	document.getElementById("itemName").value = val;
	if ((document.getElementById("times").value) == 1){
		document.getElementById("itemName").value += " One Time Donation";
	} else {
		document.getElementById("itemName").value += " Recurring Donation";
	}
}
function getPurposeChecked() 
{
	var radios = document.getElementsByName("tier2");
	for (var i=0;i<radios.length;i++){
		if (radios[i].checked){
			return radios[i].value;
		}
	}
}
function submenu(menuName)
{
	$(document).ready(function(){
		$(".subMenu").css("display", "none");
		$("#"+menuName).css("display", "block");
	});
}